<?
	include_once ("../include/conn.php");
	include_once ('config.php');
	/**************************************
	 * ***************取出题目列表***********
	 * ************************************/

	//初始化数据
	$sid = $_GET['sid'];
	// $sid = 9999999999;
	$result_empty = array('code' => 1,'msg' => '题库没有内容');//用于输出没有结果的json数组
	$results = array('code' => 0,'msg'=>'数据正常！');//用于正常有数据输出的

	////////////////////////////取出题库信息//////////////////////////
	$rsqn = mysql_query("select * from {$TABLE_C}vote_series where id=$sid");
	$qnData = mysql_fetch_assoc($rsqn);
	//写入题库的主信息
	$results['dataQn'] = Array(
		'id'      => $qnData['id'],
		'name'    => $qnData['name'],
		'payment' => $qnData['payment'],
		'price'   => $qnData['price'],
	);

	//取出问卷的分组，包含id,name的数组
	// $results['dataList'] = Array();
	$qn_gid_array = array(); 
	$rsqng = mysql_query("select * from {$TABLE_C}vote_series where forid=$sid");
	while ($row = mysql_fetch_assoc($rsqng)) {
		$results['dataList'][$row['name']] = Array(
			'id' => $row['id'],
			'name' => $row['name']
		);
		$qn_gid_array[$row['name']]=$row['id'];
	}
	// print_r($qn_gid_array);

	////////////////////////////取出题目//////////////////////////
	#遍历问题分组数组，取出题目，放到对应的数组里面
	foreach ($qn_gid_array as $key => $value) {
		$cmd = "select * from {$TABLE_C}vote_question where series=$value and isindex=1 order by orderby desc,id asc";
		$result_query = mysql_query($cmd);
		while ($row = mysql_fetch_assoc($result_query)) {
			$results['dataList'][$key]['question_list'][] = $row;
		}
	}
	
	// print_r($results);exit;
	
	// //////////////////输出数据////////////////////////////////
	echo json_encode($results);
	mysql_close();
?>